<?php $this->set('title', $this_audiencelist['Audiencelist']['name']); ?>

<?php echo $html->link('Audience Lists', array('controller'=>'Audiencelists', 'action'=>'index')); ?>

<div class="header">Edit Audience List</div>

<?php echo $form->create('Audiencelist', array('action' => 'view/'.$this_audiencelist['Audiencelist']['id'])); ?>
<table border="0" cellpadding=="0" cellspacing="0">
	<tr>
		<td class="leftcell">
			Name:
		</td>				
		<td class="rightcell">
			<?php echo($form->error('Audiencelist.name', array('class' => 'errMsg'))); ?>
			<?php echo($form->text('Audiencelist.name', array('style' => 'width:200px;', 'value'=>$this_audiencelist['Audiencelist']['name']))); ?>
		</td>
	</tr>
	<tr>
		<td class="rightcell" colspan="2">
			<?php echo $form->input('id', array('type'=>'hidden')); ?>
			<?php echo $form->end('Submit') ?>
		</td>
	</tr>
</table>

<div class="header">Audience List Members</div>

<!-- Current Audience list-->
<table border="0" cellpadding="5" cellspacing="0">
	<tr>
		<th>Username</th>
		<th>First Name</th>
		<th>Last Name</th>
	</tr>
<?php foreach ($users as $preregistered_user): ?>
	<tr>
		<td><?php echo($preregistered_user['User']['username']); ?></td>
		<td><?php echo($preregistered_user['User']['firstname']); ?></td>
		<td><?php echo($preregistered_user['User']['lastname']); ?></td>
	</tr>
<?php endforeach; ?>
</table>

<!-- Search form element -->
<?php echo $this->element('audience_member_search',
	array("controller" => "Audiencelists", "action" => "view/".$this_audiencelist['Audiencelist']['id']));?>

<!-- Audience Member Search Results -->
<?php if($display) { pr('displaying results');?>
<!-- Search results -->
<table style="" cellpadding="5" cellspacing="0" border="0">
	<tr> 
		<th><?php echo $paginator->sort('Name', 'name'); ?></th> 
		<th>Add to Audience List</th>
	</tr>
    <?php foreach($searchResults as $user): ?> 
	<tr>
		<td><?php echo $user['User']['username']; ?></td>
		<td>
			<?php echo $html->link('Add',
		 	  array('controller'=>'audiencelists', 'action' => 'addUserToAudiencelist/'.$user['User']['id'].'/'.$this_audiencelist['Audiencelist']['id']));
			 ?>
		 </td>
	</tr>
	<?php endforeach; ?>
	<tr>
		<!-- Pagination -->
		<td colspan="3">
			<!-- Shows the page numbers -->
			<?php echo $paginator->numbers(); ?>
			<br />
			<!-- Shows the next and previous links -->
			<?php
				echo $paginator->prev('« Previous ', null, null, array('class' => 'disabledPageLink'));
				echo $paginator->next(' Next »', null, null, array('class' => 'disabledPageLink'));
			?>
			<br />
			<!-- prints X of Y, where X is current page and Y is number of pages -->
			<?php echo $paginator->counter(); ?>
		</td>
	</tr>
</table>
<?php } ?>